# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.spark_submit import SparkSubmitOperator
from jms.time_sensor import time_after_01_30

nowdt = '{{ execution_date | cst_ds }}'
nextdt = '{{ execution_date | date_add(1) | cst_ds }}'
# nowdt = '{{ execution_date | date_add(1) | cst_ds }}'
filepath = f"/FinancialDataSync/ownerless_register/{nowdt}*"
filepath1 = f"/FinancialDataSync/ownerless_register/{nextdt}--00"
table = "jms_ods.ownerless_register"
outfilenum = "1"

jms_ods__ownerless_register = SparkSubmitOperator(
    task_id='jms_ods__ownerless_register',
    email=['yl_etl@yl-scm.com','yl_bigdata@yl-scm.com'],
    name='jms_ods__ownerless_register_{{ execution_date | date_add(1) | cst_ds }}',
    pool_slots=1,
    execution_timeout=timedelta(hours=1),
    driver_cores=2,
    driver_memory='4G',
    executor_cores=2,
    executor_memory='4G',
    num_executors=2,
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 18,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '2G',  # 堆外内存
          'spark.sql.shuffle.partitions': 600,
          },
    java_class='com.yunlu.bigdata.jobs.etl.MysqlDataHandle',  # spark 主类
    application='hdfs:///scheduler/jms/spark/wangbiao/hdfsloadods/MysqlDataHandle.jar',  # spark jar 包
    yarn_queue='pro',
    application_args=[filepath,filepath1,table,nowdt,outfilenum],
)
jms_ods__ownerless_register << time_after_01_30
